package com.wang.madness.customResponse;

import com.wang.madness.customEnum.ErrorShowType;
import com.wang.madness.customEnum.ResultCode;
import lombok.Data;

/**
 * @author DanielWu
 */
@Data
public class ErrorResult<T> {

  private boolean success = true;

  private T data;

  private int errorCode;

  private String errorMessage;

  private int showType = ErrorShowType.ERROR_MESSAGE.getValue();

  private String host = "127.0.0.1";

  public ErrorResult () {
    this.errorCode = ResultCode.ERROR.getCode();
    this.errorMessage = ResultCode.ERROR.getMsg();
  }

  public ErrorResult (T data) {
    this(ResultCode.SUCCESS, data);
  }

  public ErrorResult (int code, String msg) {
    this.errorCode = code;
    this.errorMessage = msg;
  }

  public ErrorResult (ResultCode resultCode) {
    this.errorCode = resultCode.getCode();
    this.errorMessage = resultCode.getMsg();
  }

  public ErrorResult (ResultCode resultCode, T data) {
    this.errorCode = resultCode.getCode();
    this.errorMessage = resultCode.getMsg();
    this.data = data;
  }

  public ErrorResult (int code, String msg, T data) {
    this.errorCode = code;
    this.errorMessage = msg;
    this.data = data;
  }

  public ErrorResult(boolean success, T data, ResultCode resultCode, ErrorShowType errorShowType, String host) {
    this.success = success;
    this.data = data;
    this.errorCode = resultCode.getCode();
    this.errorMessage = resultCode.getMsg();
    this.showType = errorShowType.getValue();
    this.host = host;
  }

  public static<T> ErrorResult<T> error(){
    return new ErrorResult<>();
  }

  public static<T> ErrorResult<T> error(T data){
    return new ErrorResult<>(data);
  }

}
